package com.myschool.dao.impl;

import com.myschool.dao.StudentDao;
import com.myschool.pojo.Student;
import com.myschool.util.BaseDao;

import java.util.List;

public class StudentDaoImpl implements StudentDao {
    @Override
    public int add(Student student) {
        String sql = "INSERT INTO student(studentno,loginpwd,studentname,sex,gradeid,phone,address,bornDate,email,) values(?,?,?,?,?,?,?,?,?)";
        return BaseDao.executeUpdate(sql,student.getStudentNo(),student.getLoginPwd(),student.getStudentName(),student.getSex(),student.getGradeId(),student.getPhone(),student.getAddress(),student.getBornDate(),student.getEmail());
    }

    @Override
    public int deleteStudent(int studentno) {
        String sql = "delete from grade where studentno=?;";
        return BaseDao.executeUpdate(sql,studentno);
    }

    @Override
    public int updateStudent(Student student) {
        String sql = "update student set studentname = ? where studentno = ?;";
        return BaseDao.executeUpdate(sql,student.getStudentName(),student.getStudentNo());
    }


    @Override
    public List show(Class classz) {
        String sql = "select * from"+"  "+classz.getSimpleName();
        return  BaseDao.show(sql,classz);
    }

    @Override
    public List findByStudentno(int id, Class classz) {
        String sql = "select * from"+"  "+classz.getSimpleName()+"where studentno="+id;
        return BaseDao.show(sql,classz,id);
    }
}
